package com.mzj.saas.mservice.community.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.community.service.CommunityService;
import com.mzj.saas.mservice.community.vo.CommunityVO;
import com.mzj.saas.mservice.house.vo.HouseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 小区接口
 */
@Controller
@RequestMapping("/community")
@Api(tags = "小区接口")
public class CommunityController {
    @Autowired
    private CommunityService communityService;

    /**
     * 查询小区
     *
     */
    /**
     * 查询小区,实现了根据不同的用户查询出用户下面对应的小区数据
     * @param accessToken 权限鉴定
     * @return
     */
    @GetMapping("/findCommunity")
    @ResponseBody
    public ResultBean<List<Map<String, Object>>> findCommunity(@RequestHeader String accessToken) {
        return communityService.findCommunity(accessToken);
    }

    /**
     * 查询楼栋-公租房+房产
     *
     */
    @GetMapping("/findBuild")
    @ResponseBody
    public ResultBean<List<Map<String, Object>>> findBuild(@RequestParam(value = "communityId") String communityId) {
        return communityService.findBuild(communityId);
    }

    /**
     * 查询楼栋-公租房
     *
     */
    @GetMapping("/findHouseBuild")
    @ResponseBody
    public ResultBean<List<Map<String, Object>>> findHouseBuild(@RequestParam(value = "communityId") String communityId) {
        return communityService.findHouseBuild(communityId);
    }

    /**
     * 查询单元
     *
     */
    @GetMapping("/findUnit")
    @ResponseBody
    public ResultBean<List<Map<String, Object>>> findUnit(@RequestParam(value = "communityId") String communityId,
                                                          @RequestParam(value = "buildId") Long buildId) {
        return communityService.findUnit(communityId, buildId);
    }

    /**
     * 查询房号[公租房]
     *
     */
    @GetMapping("/findRoomNumber")
    @ResponseBody
    public ResultBean<List<String>> findRoomNumber(@RequestParam(value = "communityId") String communityId,
                                                   @RequestParam(value = "buildId") Long buildId,
                                                   @RequestParam(value = "unitId") Long unitId) {
        return communityService.findRoomNumber(communityId, buildId, unitId);
    }


    /**
     * 查询房号[公租房+非公租房]
     *
     */
    @GetMapping("/findRoomNumberAll")
    @ResponseBody
    public ResultBean<List<String>> findRoomNumberAll(@RequestParam(value = "communityId") String communityId,
                                                   @RequestParam(value = "buildId") Long buildId,
                                                   @RequestParam(value = "unitId") Long unitId) {
        return communityService.findRoomNumberAll(communityId, buildId, unitId);
    }


    /**
     * 查询小区下所有楼-->房号[公租房]
     *  chargeType 收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金)
     *  chargeMode 计费方式:1按月 2按季 3按半年 4按年
     */
    @GetMapping("/findBuildUnitRoomNumber")
    @ResponseBody
    public ResultBean<List<Map<String, Object>>> findBuildUnitRoomNumber(@RequestParam(value = "communityId") String communityId,
                                                                         Integer chargeType,Integer chargeMode) {
        return communityService.findBuildUnitRoomNumber(communityId,chargeType,chargeMode);
    }

    /**
     * 查询小区下所有楼-->房号[物业房产]
     *  expenseId 物业房产-收费项目id   [saas_estate_expense_other]
     *  chargeType 收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金)
     *  chargeMode 计费方式:1按月 2按季 3按半年 4按年
     */
    @GetMapping("/findCommunityHouse")
    @ResponseBody
    public ResultBean<List<Map<String, Object>>> findCommunityHouse(@RequestParam(value = "communityId") String communityId,
                                                                    String expenseId, Integer chargeType, Integer chargeMode) {
        return communityService.findCommunityHouse(communityId, expenseId,chargeType,chargeMode);
    }

    /**
     * 公租房房源录入--导入
     */
    /**
     * 公租房房源录入--导入,实现公租房房源录入--导入
     * @param accessToken 权限鉴定
     * @param mfile 公租房房源录入的文件
     * @param residenceCommunityId 公租房房源小区ID
     * @return
     */
    @RequestMapping(value = "houseImport" , method = RequestMethod.POST)
    @ResponseBody
    public ResultBean<Object> houseImport(@RequestHeader String accessToken,
                                          @RequestParam("file") MultipartFile mfile,
                                          @RequestParam(name = "residenceCommunityId", required = false) String residenceCommunityId){

        return communityService.houseImport(accessToken,mfile,residenceCommunityId);
    }


    /**
     * 物业房产录入--导入
     */
    @RequestMapping(value = "communityHouseImport" , method = RequestMethod.POST)
    @ResponseBody
    public ResultBean<Object> communityHouseImport(@RequestHeader String accessToken,
                                                   @RequestParam("file") MultipartFile mfile,
                                                   @RequestParam(name = "residenceCommunityId", required = false) String residenceCommunityId,
                                                   @RequestParam(name = "housePropertyId", required = false) Long housePropertyId){

        return communityService.communityHouseImport(accessToken,mfile,residenceCommunityId, housePropertyId);
    }

    /**
     *小区 --导入
     */
    @RequestMapping(value = "communityImport" , method = RequestMethod.POST)
    @ResponseBody
    public ResultBean<Object> communityImport(@RequestHeader String accessToken,
                                     @RequestParam("file") MultipartFile mfile){

        return communityService.communityImport(accessToken,mfile);
    }

    /**
     * 小区--导出
     */
    @GetMapping("/communityExport")
    @ResponseBody
    public void communityExport(@RequestHeader String accessToken, HttpServletResponse response, CommunityVO vo,@RequestParam(required = false) List<String> idList) throws Exception {

        communityService.communityExport(accessToken, response, vo, idList);
    }

    /**
     * 公租房--导出
     */
    /**
     * 公租房--导出实现公租房数据的导出
     * @param accessToken           权限鉴定
     * @param response              响应
     * @param pageNumber           当前页
     * @param pageSize             页数
     * @param residenceCommunityId 小区id
     * @param buildingNum          楼栋
     * @param unit                 单元
     * @param roomNumber           房号
     * @param districtId           区
     * @param bindStatus           产权人绑定状态:0未绑定 1绑定
     * @param matchStatus          配租状态：0未配租 1可配租 2已配租
     * @param leaseStatus          出租状态：0未出租 1已出租
     * @param pwdLockStatus        密码锁授权：0未授权 1已授权 4已冻结
     * @param houseNature          性质:1公租房、2廉租房、3商品房、4经济适用房、5其它
     * @param checkStatus          核查状态：0未核查、1已核查
     * @param orgId                组织id
     * @param search               搜索条件
     * @param houseId              房屋id
     * @param floor                楼层
     * @param area                 面积
     * @param decorateType         装修
     * @param provinceId           省
     * @param cityId               市
     * @param streetId             街道
     * @param communityId          社区
     * @param address              地址
     * @param auditStatus          房源审核状态:0未审核 1已审核
     * @param room                 室
     * @param hall                 厅
     * @param toilet               卫
     * @param houseIdList          房屋id集合
     * @throws Exception
     */
    @GetMapping("/houseExport")
    @ResponseBody
    public void houseExport(@RequestHeader String accessToken, HttpServletResponse response,
                            @RequestParam(defaultValue = "0") Integer pageNumber,
                            @RequestParam(defaultValue = "5") Integer pageSize,
                            @RequestParam(required = false) String residenceCommunityId,
                            @RequestParam(required = false) Long buildingNum,
                            @RequestParam(required = false) Long unit,
                            @RequestParam(required = false) String roomNumber,
                            @RequestParam(required = false) Long districtId,
                            @RequestParam(required = false) Integer bindStatus,
                            @RequestParam(required = false) Integer matchStatus,
                            @RequestParam(required = false) Integer leaseStatus,
                            @RequestParam(required = false) Integer pwdLockStatus,
                            @RequestParam(required = false) Integer houseNature,
                            @RequestParam(required = false) Integer checkStatus,
                            @RequestParam(required = false) Long orgId,
                            @RequestParam(required = false) String search,
                            @RequestParam(required = false) String houseId,
                            @RequestParam(required = false) Integer floor,
                            @RequestParam(required = false) BigDecimal area,
                            @RequestParam(required = false) Integer decorateType,
                            @RequestParam(required = false) Long provinceId,
                            @RequestParam(required = false) Long cityId,
                            @RequestParam(required = false) Long streetId,
                            @RequestParam(required = false) Long communityId,
                            @RequestParam(required = false) String address,
                            @RequestParam(required = false) Integer auditStatus,
                            @RequestParam(required = false) Integer room,
                            @RequestParam(required = false) Integer hall,
                            @RequestParam(required = false) Integer toilet,
                            @RequestParam(required = false) List<String> houseIdList) throws Exception {

        communityService.houseExport(accessToken, pageNumber, pageSize, residenceCommunityId, buildingNum, unit, roomNumber,
                districtId, bindStatus, matchStatus, leaseStatus, pwdLockStatus, houseNature, checkStatus, orgId, search,
                houseId, floor, area, decorateType, provinceId, cityId, streetId, communityId, address, auditStatus,room,hall,toilet,houseIdList,response);
    }

    /**
     * 非公租房--导出
     */
    @GetMapping("/communityHouseExport")
    @ResponseBody
    public void communityHouseExport(@RequestHeader String accessToken, HttpServletResponse response, HouseVO vo,@RequestParam(required = false) List<String> houseIdList) throws Exception {

        communityService.communityHouseExport(accessToken, response, vo,houseIdList);
    }

    /**
     * 公租房房源录入模板下载
     */
    /**
     * 公租房房源录入模板下载,实现了用户对公租房房源录入模板下载
     * @param accessToken 权限鉴定
     */
    @GetMapping("/houseDownload")
    public void houseDownload(@RequestHeader String accessToken) {
        this.communityService.houseDownload(accessToken);
    }

    /**
     * 非公租房录入模板下载
     */
    @GetMapping("/communityHouseDownload")
    public void communityHouseDownload(@RequestHeader String accessToken) {
        this.communityService.communityHouseDownload(accessToken);
    }

    /**
     * 小区导入模板下载
     */
    @GetMapping("/communityDownload")
    public void communityDownload(@RequestHeader String accessToken) {
        this.communityService.communityDownload(accessToken);
    }

    /**
     * 查询房屋类型
     *
     */
    @GetMapping("/findHouseType")
    @ResponseBody
    @ApiOperation("查询房屋类型")
    public ResultBean<Object> findHouseType(@RequestHeader String accessToken) {
        return communityService.findHouseType(accessToken);
    }

}
